package com.demo.deal_service.model.entity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import javax.validation.constraints.*;
import java.util.Date;

/***
 * 商品实体类
 * FIXME 日期用long类型
 */
@Data
@EqualsAndHashCode
public class Deal {
    @NotNull
    @Min(0)
    private Long id;//主键id

    @NotNull
    @Size(max = 64)
    private String merchantName;//商家名称

    @NotNull
    @Size(max = 64)
    private String merchantAddress;//商家地址

    @NotNull
    @Size(max = 200)
    private String dealTitle;//商品标题

    @NotNull
    @DecimalMin("0")
    @DecimalMax("10000000")
    private Double dealPrice;//商品价格

    @NotNull
    @Max(100)
    @Min(1)
    private Integer discount;//商品折扣 范围1-100

    @NotNull
    private Integer dealType;//商品类型

    private String imageUrl;//图像地址

    @NotNull
    private Integer publishStatus;//发布状态

    @NotNull
    @Max(10000000)
    @Min(0)
    private Integer inventoryAmount;//库存数量

    @NotNull
    @Max(10000000)
    @Min(0)
    private Integer vendibilityAmount;//可售数量

    @NotNull
    private Date startTime;//开始销售时间

    @NotNull
    private Date endTime;//结束销售时间

    @NotNull
    private Date publishTime;//发布时间

    private Date createTime;//创建时间

    private Date updateTime;//更新时间

    @NotNull
    @Size(max = 100)
    private String category;//类别

    @NotNull
    @Size(max = 2000)
    private String remark;//备注信息

//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//
//        if (o == null || getClass() != o.getClass()) return false;
//
//        Deal deal = (Deal) o;
//
//        return new EqualsBuilder()
//                .append(getMerchantName(), deal.getMerchantName())
//                .append(getMerchantAddress(), deal.getMerchantAddress())
//                .append(getDealTitle(), deal.getDealTitle())
//                .append(getDealPrice(), deal.getDealPrice())
//                .append(getDiscount(), deal.getDiscount())
//                .append(getDealType(), deal.getDealType())
//                .append(getImageUrl(), deal.getImageUrl())
//                .append(getPublishStatus(), deal.getPublishStatus())
//                .append(getInventoryAmount(), deal.getInventoryAmount())
//                .append(getVendibilityAmount(), deal.getVendibilityAmount())
//                .append(getStartTime().toString(), deal.getStartTime().toString())
//                .append(getEndTime().toString(), deal.getEndTime().toString())
//                .append(getPublishTime().toString(), deal.getPublishTime().toString())
//                .append(getCreateTime().toString(), deal.getCreateTime().toString())
//                .append(getUpdateTime().toString(), deal.getUpdateTime().toString())
//                .append(getCategory(), deal.getCategory())
//                .append(getRemark(), deal.getRemark())
//                .isEquals();
//    }
//
//    @Override
//    public int hashCode() {
//        return new HashCodeBuilder(17, 37)
//                .append(getMerchantName())
//                .append(getMerchantAddress())
//                .append(getDealTitle())
//                .append(getDealPrice())
//                .append(getDiscount())
//                .append(getDealType())
//                .append(getImageUrl())
//                .append(getPublishStatus())
//                .append(getInventoryAmount())
//                .append(getVendibilityAmount())
//                .append(getStartTime().getTime())
//                .append(getEndTime().getTime())
//                .append(getPublishTime().getTime())
//                .append(getCreateTime().getTime())
//                .append(getUpdateTime().getTime())
//                .append(getCategory())
//                .append(getRemark())
//                .toHashCode();
//    }

    @Override
    public String toString() {
        return "Deal{" +
                "id=" + id +
                ", merchantName='" + merchantName + '\'' +
                ", merchantAddress='" + merchantAddress + '\'' +
                ", dealTitle='" + dealTitle + '\'' +
                ", dealPrice=" + dealPrice +
                ", discount=" + discount +
                ", dealType=" + dealType +
                ", imageUrl='" + imageUrl + '\'' +
                ", publishStatus=" + publishStatus +
                ", inventoryAmount=" + inventoryAmount +
                ", vendibilityAmount=" + vendibilityAmount +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", publishTime=" + publishTime +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", category='" + category + '\'' +
                ", remark='" + remark + '\'' +
                '}';
    }
}
